package cn.rocksolid.proxy.restful.sys;

import cn.rocksolid.sport.common.context.RockSolidContextHolder;
import cn.rocksolid.sport.security.service.MenuService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * System menu service
 *
 * @author Axl Zhaos
 * @email axl.zhao@163.com
 */
@RestController
@RequestMapping("/sys/menu")
public class MenuController {

  private final MenuService menuService;

  @Autowired
  public MenuController(final MenuService menuService) {
    this.menuService = menuService;
  }

  /**
   * Navigation menu and current user permissions.
   */
  @GetMapping
  @RequiresAuthentication
  public Object menus() {
    return menuService.queryMenusByUid(RockSolidContextHolder.getContextSafe().getAccessId());
  }
}
